{include file="public/header" /}
<body>
<div class="layui-card">
    <div class="layui-card-body">
        <div class="layui-tab-content">
            <form id="forbiddenForm" class="layui-form layui-form-pane" autocomplete="off">
                <div class="layui-form-item">
                    <label class="layui-form-label layui-required">起始</label>
                    <div class="layui-input-block">
                        <input type="text" name="start" id="ipStart" class="layui-input" placeholder="请输入IP段起始值。例：192.168.0.0">
                    </div>
                </div>

                <div class="layui-form-item">
                    <label class="layui-form-label layui-required">结束</label>
                    <div class="layui-input-block">
                        <input type="text" name="end" id="ipEnd" class="layui-input" placeholder="请输入IP段结束值。例：192.168.255.255">
                    </div>
                </div>

                <div class="btn-block">
                    <button type="button" onclick="sendForbidden()" class="layui-btn layui-btn-normal"><i class="fa fa-check"></i>提交</button>
                    <button type="reset" class="layui-btn layui-btn-primary"><i class="fa fa-refresh"></i>重置</button>
                </div>
            </form>
        </div>
    </div>
</div>
</body>

<script>
    layui.use('form',function () {
        var $ = layui.jquery,
            form = layui.form;
    })

    function sendForbidden() {
        var ipReg = /^(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])\.(\d{1,2}|1\d\d|2[0-4]\d|25[0-5])$/

        if (!ipReg.test($('#ipStart').val())){
            hintMsg('请输入正确格式的IP地址','ipStart')
            return false
        } else if(!ipReg.test($('#ipEnd').val())){
            hintMsg('请输入正确格式的IP地址','ipEnd')
            return false
        }

        //弹出遮罩层，防止多次点击
        var forbiddenLoad = layer.load(1,{shade:[0.5,'#FFF'],time:0})
        let data = $("#forbiddenForm").serialize()
        ajaxRequest("{:url('Forbidden/add')}",data,function (res) {
            if (res.code == 'suc'){
                sucMsg(res.msg,function () {
                    //刷新父级页面
                    parent.layui.table.reload('ipList')
                    //关闭遮罩层
                    layer.close(forbiddenLoad)
                    //关闭当前弹出层
                    xadmin.close()
                })
            }else {
                errMsg(res.msg,function () {
                    //关闭遮罩层
                    layer.close(forbiddenLoad)
                })
            }
        })
    }
</script>